import random

myuser = {12345678:{"姓名":"张三","密码":123456,"地址":"河南郑州","存款余额":1000,"开户行":"中国工商银行郑州分行"}}

def userAdd():
        user = random.randint(10000000, 99999999)
        if user in myuser:
            print("账号已存在")
            return 2
        if len(myuser)>100:
            print("用户已满")
            return 3
        print("你的账号是："+str(user))
        name = input("输入姓名：")
        pwd = input("输入密码：")
        while len(pwd) != 6:
            print("请输入6位数的密码")
            pwd = input("输入密码：")
        dress = input("输入地址：")
        money = 0
        bank = "中国工商银行郑州分行"
        myuser[user] = {"姓名": name, "密码": int(pwd), "地址": dress, "存款余额": money, "开户行": bank}
        return 1

def savemoney():
        user = int(input("输入你的账号："))
        if user not in myuser:
            print("没有该用户，请检查账号是否正确！")
            return False
        money = int(input("输入存款数量："))
        money = money + myuser[user]["存款余额"]
        myuser[user]["存款余额"] = money
        # print(myuser[user])
        # list()
        return True

def getmoney():
    user = int(input("输入你的账号："))
    if user not in myuser:
        print("没有该用户，请检查账号是否正确！")
        return 1
    ps = int(input("输入你的密码："))
    if ps != myuser[user]["密码"]:
        print("密码错误！")
        return 2
    gtm = int(input("输入你要取钱的数量："))
    if gtm > myuser[user]["存款余额"]:
        print("余额不足")
        return 3
    else:
        myuser[user]["存款余额"] = myuser[user]["存款余额"] -gtm
        print("取钱成功！")

def transfer():
    userout = int(input("输入转出账号："))
    userin = int(input("输入转入账号："))
    if userin not in myuser or userout not in myuser:
        print("账号不存在")
        return 1
    pwdout = int(input("输入转出账号的密码："))
    if pwdout != myuser[userout]["密码"]:
        print("密码错误")
        return 2
    moneyout = int(input("输入转出的金额："))
    if moneyout > myuser[userout]["存款余额"]:
        print("余额不足！")
        return 3
    myuser[userout]["存款余额"] -= moneyout
    myuser[userin]["存款余额"] += moneyout
    print("转账成功！")
    return 0

def list():
    # print(f"{'账号':<10}{'姓名':<15}{'密码':<15}{'地址':<15}{'存款余额':<15}{'开户行':<15}")
    # for i in myuser:  # 从字典中取出
    #     print(f"{i:<8}{myuser[i]['姓名']:>5}{myuser[i]['密码']:>17}{myuser[i]['地址']:>14}{myuser[i]['存款余额']:>18}"
    #           f"{myuser[i]['开户行']:>13}")
    user = int(input("输入你的账号："))
    if user not in myuser:
        print("该用户不存在！")
    ps = int(input("输入你的密码："))
    if ps != myuser[user]['密码']:
        print("密码错误！")
    print(f"当前账号：{user},密码：{myuser[user]['密码']},账户余额：{myuser[user]['存款余额']},用户居住地址：{myuser[user]['地址']},"
          f"当前开户行：{myuser[user]['开户行']}")

while True:
    print("中国工商银行".center(50, "*"))
    print("账户管理系统".center(50, " "))
    print("V 1.0".center(50, " "))
    print("".center(50, " "))
    print("".center(54, "*"))

    print("1、开户")
    print("2、存钱")
    print("3、取钱")
    print("4、转账")
    print("5、查询")
    print("6、Bye")

    option = input("请输入你的选择：")
    if option == '1':
        userAdd()
    elif option == '2':
        savemoney()
    elif option == '3':
        getmoney()
    elif option == '4':
        transfer()
    elif option == '5':
        list()
    elif option == '6':
        break
    else:
        print("输入正确数字")
        continue

    # print("".center(54, "*"))





